//
//  FirstViewController.swift
//  CMCCIOTSwift
//
//  Created by isoftstone on 2017/4/18.
//  Copyright © 2017年 isoftstone. All rights reserved.
//

import SnapKit
import UIKit
import Alamofire
class FirstViewController: BaseViewController {

    
    var btn : UIButton?
    var  dataProvider  =  DataProvider<RequestProtocol>()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "test"
        // Do any additional setup after loading the view.
        btn = UIButton()
        self.view .addSubview(btn!)
        
        btn?.snp.makeConstraints({ (maker) in
            maker.width.height.equalTo(50)
            maker.center.equalTo(self.view)
        })
        
        btn?.setTitle("测试", for: .normal)
        btn?.addTarget(self, action: #selector(btnAction(sender:)), for:.touchUpInside )
        self.view.backgroundColor = UIColor.white
        
//       let request = Alamofire.request("https://rxswift.leanapp.cn/users", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil);
//        request.responseJSON { (response) in
//            
//            print(response)
//        }
        
        self.startLoading("正在加载...")
//        CommonNetWorkKit.shared.post(params: [:]) { (response, result) in
//            self .showInfo("加载成功")
//        }
        
//        dataProvider.requestJSON(target: .Users,returnVal: { returnVal in
//            print(returnVal)
//            let value = returnVal as NSDictionary;
//            if let test = TestModel.deserialize(from:value){
//                for user in (test.data?.users)!
//                {
//                    print(user.name)
//                }
//            }
//        }, failur:{error in
//            print(error)
//            
//            
//        })
//        
//        let dataTestProvider = DataProvider<URLTest>()
//        dataTestProvider.requestJSON(target: URLTest(), returnVal: { (returnVal) in
//            let value = returnVal as NSDictionary;
//            if let test = TestModel.deserialize(from:value){
//                for user in (test.data?.users)!
//                {
//                    print(user.name)
//                }
//            }
//        }) { (error) in
//            
//        }
        //dataProvider.requestData(target: .Users)
        
        let entinry = EntinrtyTest()
//        entinry.foo = ["1","2","3"]
//       let en = Entinrty()
//       en.baz = "qux"
//        entinry.bar = en
       entinry.name = "user"
        let dataEntinrtyProvider = DataProvider<EntinrtyTest>()
        dataEntinrtyProvider.requestJSON(target: entinry, returnVal: { (returnVal) in
            let value = returnVal as NSDictionary;
            if let test = TestModel.deserialize(from:value){
                for user in (test.data?.users)!
                {
                    //print(user.name)
                }
                self .stopLoading()
            }

        }) { (error) in
            
        }
        
        
//        let parameters: Parameters = [
//            "foo": [1,2,3],
//            "bar": [
//                "baz": "qux"
//            ]
//        ]
//        let headers: HTTPHeaders = [
//            "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
//            "Accept": "application/json"
//        ]
//        
//         var urlString = "https://httpbin.org/get"
//        Alamofire.request(urlString, method: .get, parameters: parameters, encoding: URLEncoding.default, headers: headers).responseJSON { (respond) in
//            if let JSON = respond.result.value {
//                print("JSON: \(JSON)")
//            }
//            
//        }
    
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    func btnAction(sender : UIButton)  {
        
    }
   
    
}
